import * as MUTATIONS_TYPE from './mutations_type';

const mutations = {
  [MUTATIONS_TYPE.UPDATE_MOCKS_STATUS] (state, mocksStatus) {
    state.mocksStatus = mocksStatus;
  },
  [MUTATIONS_TYPE.UPDATE_CURRENT_PART](state, currentPart) {
    state.currentPart = currentPart;
    if (state.paperInfo && state.paperInfo.part_list && state.currentPart) {
      state.partInfo = state.paperInfo.part_list[state.currentPart - 1];
    }
  },
  [MUTATIONS_TYPE.UPDATE_TOTAL_PART] (state, totalPart) {
    state.totalPart = toolbar;
  },
  [MUTATIONS_TYPE.UPDATE_PAPER_ID] (state, paperId) {
    state.paperId = paperId;
  },
  [MUTATIONS_TYPE.UPDATE_COURSE_ID] (state, courseId) {
    state.courseId = courseId;
  },
  [MUTATIONS_TYPE.UPDATE_PAPER_TYPE] (state, paperType) {
    state.paperType = paperType;
  },
  [MUTATIONS_TYPE.UPDATE_PAPER_INFO] (state, paperInfo ) {
    state.paperInfo = paperInfo;
    if (paperInfo) {
      if (paperInfo.total_part) {
        state.totalPart = (typeof paperInfo.total_part === 'string') ? parseInt(paperInfo.total_part) : paperInfo.total_part;
      }
      if (paperInfo.test_time) {
        state.testTime = (typeof paperInfo.test_time === 'string') ? parseInt(paperInfo.test_time) : paperInfo.test_time;
      }
      if (paperInfo.total_score) {
        state.totalScore = (typeof paperInfo.total_score === 'string') ? parseInt(paperInfo.total_score) : paperInfo.total_score;
      }
      if (paperInfo.paper_type) {
        state.paperType = paperInfo.paper_type;
      }
      if (paperInfo.paper_type_name) {
        state.paperTypeName = paperInfo.paper_type_name;
      }
      if (paperInfo.part_list && state.currentPart) {
        state.partInfo = paperInfo.part_list[state.currentPart - 1];
      }
    }
  },
  [MUTATIONS_TYPE.UPDATE_TEST_TIME] (state, testTime) {
    state.testTime = testTime;
  },
  [MUTATIONS_TYPE.UPDATE_TOTAL_SCORE] (state, totalScore) {
    state.totalScore = totalScore;
  },
  [MUTATIONS_TYPE.UPDATE_DISABLE_PREV_BTN] (state, disabledPrevBtn) {
    state.disablePrevBtn = disabledPrevBtn;
  },
  [MUTATIONS_TYPE.UPDATE_DISABLE_NEXT_BTN] (state, disableNextBtn) {
    state.disableNextBtn = disableNextBtn;
  },
  [MUTATIONS_TYPE.UPDATE_IS_ALLOW_RECORD] (state, isAllowRecord) {
    state.isAllowRecord = isAllowRecord;
  },
  [MUTATIONS_TYPE.UPDATE_QUESTION_NUM] (state, questionNum) {
    state.questionNum = questionNum;
  },
  [MUTATIONS_TYPE.UPDATE_MP3RECODER] (state, mp3Reacorder) {
    state.mp3Recorder = mp3Reacorder;
  },
  [MUTATIONS_TYPE.UPDATE_SHOW_HEADER_PART] (state, showHeaderPart) {
    state.showHeaderPart = showHeaderPart;
  }
};

export default mutations;
